package web2.config;

import framework.config.SecurityConfig;
import framework.security.AccountLoader;
import framework.security.FunctionPermission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import security.config.SecurityConfiguration;
import system.security.AccountLoaderImpl;

import java.util.List;

/**
 * 用户安全组件配置
 */
@Slf4j
@Component
public class UserSecurityConfig extends SecurityConfiguration {

    @Override
    public AccountLoader newAccountLoader(SecurityConfig securityConfig) {
        return new AccountLoaderImpl();
    }

    /**
     * 重载功能项列表，你可以在此加入或修改应用需要鉴权的路径
     *
     * @param securityConfig
     * @return
     */
    @Override
    protected List<FunctionPermission> loadFunctionPermissionList(SecurityConfig securityConfig) {
        List<FunctionPermission> fpl = super.loadFunctionPermissionList(securityConfig);
        //你可以在此添加你自已定义的配置表或修改原有配置
//                fpl.add(new FunctionPermission("/path/list", "permission", null));
//                fpl.add(new FunctionPermission("/path/edit", "permission.edit", "POST"));
        //需要授权才能访问的动态文件
        fpl.add(new FunctionPermission("/file/s/**", "AUTH", null));
        //我的账号信息
        fpl.add(new FunctionPermission("/my/**", "AUTH", null));
        return fpl;
    }

    /**
     * 重载匿名路径表，
     *
     * @param securityConfig
     * @return
     */
    @Override
    protected List<String> loadAnonymousPaths(SecurityConfig securityConfig) {
        List<String> anonymousPaths = super.loadAnonymousPaths(securityConfig);
        // 允许匿名访问的文件的动态文件
        anonymousPaths.add("/file/g/**");
        // 你可以在此添加你自已的配置表或修改原有配置
//                anonymousPaths.add("/**/*.html");
        anonymousPaths.add("/pub/**");
        return anonymousPaths;
    }


}
